#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 2e3 + 10;
int arr[N];
int f[N][N];
int n, k;
int main()
{
	while (cin >> n >> k) {
		memset(arr, 0, sizeof(arr));
		memset(f, 0x3f, sizeof(f));
		for (int i = 1; i <= n; i++) {
			cin >> arr[i];
		}
		sort(arr + 1, arr + n + 1);
		for (int i = 0; i <= n; i++) {
			f[i][0] = 0;
		}
		for (int i = 2; i <= n; i++) {
			for (int j = 1; j * 2 <= i; j++) {
				int t = arr[i] - arr[i - 1];
				f[i][j] = min(f[i - 1][j], f[i - 2][j - 1] + t * t);
			}
		}
		cout << f[n][k] << endl;
	}
	return 0;
}